<?php
if($_POST['act']=='export' && $_POST['order_ids']!=""){
	include_once '../lib/php_excel.php';
	include_once("../module/product/includes/plugin_order_class.php");
	$order = new order;
	$general_shop =$order->get_general_shop();
	$order_ids = str_replace("，", ",", $_POST['order_ids']);
	$export_sql = "select a.*,b.pname as name,b.pid as pid, b.spec,b.code from ".ORPRO." a left join ".SETMEAL." b on a.product_id=b.id where a.order_id IN({$order_ids})";
	if ($general_shop){
		$export_sql .=" and stock_shop = '$general_shop' ";
	}
	$db->query($export_sql);
	$products=$db->getRows();
	$export_data = array();
	foreach ($products as $key=> $var)
	{
		$export_data[$key]['order_id'] = $var['order_id'];
		$export_data[$key]['code'] = $var['code'];
		$export_data[$key]['product_id'] = $var['pid'];
		$export_data[$key]['product_name'] = $var['name']." ".$var['spec'];
		$export_data[$key]['price'] = $var['price'];
		$export_data[$key]['num'] = $var['num'];
		$export_data[$key]['is_stocked_str'] = $var['is_stocked']=='-1'?'未出库':($var['is_stocked']=='1'?'已出库':'未处理');
	}
	$queue[0] = array("订单编号","商品编号","商品ID","商品名称","单价","数量","出库状态");//定义表头
	$export_data = array_merge($queue,$export_data);
	//print_r($export_data);
	$filename =   "订单商品信息" . date ( "YmdHis" );
	$xls = new Excel_XML ( 'UTF-8', false, '订单信息' );
	$xls->addArray ( $export_data );
	$xls->generateXML ( $filename );
	exit ();
}
$tpl->display("order_products_export.htm");
?>